{include file='public/meta' }
<title>会员列表 - 木鱼内容管理系统</title>
</head>
<body>
<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-form layui-card-header layuiadmin-card-header-auto">
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">会员查找</label>
					<div class="layui-input-block">
						<input type="text" name="keywords" id="keywords" placeholder="请输入关键词" autocomplete="off" class="layui-input">
					</div>
				</div>


				<div class="layui-inline">
					<button class="layui-btn layuiadmin-btn-useradmin" type="submit" onclick="so()">
						<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
					</button>
				</div>
			</div>
		</div>

		<div class="layui-card-body">
			<div style="padding-bottom: 10px;">
				<button class="layui-btn layui-btn-danger layuiadmin-btn-useradmin" onclick="delAll()">批量删除</button>
				<button class="layui-btn layuiadmin-btn-useradmin" onclick="openwind('添加会员','{:url('member/add')}','{:url('member/add')}')">添加</button>
			</div>


			<div class="layui-table-body layui-table-main">
				<table class="layui-table">
					<thead>
					<tr>
						<th class=" layui-table-col-special">
							<div class="layui-table-cell laytable-cell-checkbox">
								<input type="checkbox" id="checkAll" onclick="isCheck()">
							</div>
						</th>
						<th><div class="layui-table-cell" align="center"><span>ID</span></div></th>
						<th><div class="layui-table-cell" align="center"><span>会员账户</span></div></th>
						<th><div class="layui-table-cell" align="center"><span>昵称</span></div></th>
						<th><div class="layui-table-cell" align="center"><span>性别</span></div></th>
						<th><div class="layui-table-cell" align="center"><span>余额</span></div></th>
						<th><div class="layui-table-cell" align="center"><span>总消费</span></div></th>
						<th><div class="layui-table-cell" align="center"><span>手机</span></div></th>
						<th><div class="layui-table-cell" align="center"><span>邮箱</span></div></th>
						<th><div class="layui-table-cell" align="center"><span>加入时间</span></div></th>
						<th><div class="layui-table-cell" align="center"><span>状态</span></div></th>
						<th><div class="layui-table-cell" align="center"><span>操作</span></div></th>
					</tr>
					</thead>
					<tbody>
					{foreach $member as $v}
					<tr align="center">
						<td class="layui-table-col-special">
							<input type="checkbox" name="fav" value="{$v.id}">
						</td>
						<td>{$v.id}</td>
						<td>{$v.account}</td>
						<td>{$v.name}</td>
						<td>{$v.sex}</td>
						<td><a title="点击充值" href="javascript:void(0)" onclick="addMoney('{$v.id}')" style="color:green">{$v.money}</a></td>
						<td>{$v.total}</td>
						<td>{$v.phone}</td>
						<td>{$v.email}</td>
						<td>{:date('Y-m-d',$v.create_time)}</td>
						<td><div class="layui-table-cell">
							<button type="button" class="layui-btn-xs layui-btn layui-btn-{php}echo $v['status']=='已启用' ? 'btn':'danger';{/php}">{$v.status}</button>
						</div>
						</td>
						<td align="center" data-off="true" class="layui-table-col-special">
							<div class="layui-table-cell">
								<button type="button" class="layui-btn layui-btn-xs layui-btn-{php}echo $v['status']=='已启用' ? 'danger':'btn';{/php}" onclick="setStatus('{$v.id}')"><i class="layui-icon layui-icon-{php}echo $v['status']=='已启用' ? 'download-circle':'upload-circle';{/php}"></i>{php}echo $v['status']=='已启用' ? '停用':'启用';{/php}</button>
								<button type="button" class="layui-btn layui-btn-xs" onclick="openwind('会员编辑','{:url('member/edit')}'+'?id='+{$v.id},'{:url('member/edit')}')"><i class="layui-icon layui-icon-edit"></i>编辑</button>
								<button type="button" class="layui-btn layui-btn-xs layui-btn-danger del" data-name="{$v.name}" data-id="{$v.id}"><i class="layui-icon layui-icon-delete"></i>删除</button>
							</div>
						</td>
					</tr>
					{/foreach}
					</tbody>
				</table>
			</div>
			<div class="layui-box layui-laypage layui-laypage-molv">{$member|raw}</div>
		</div>
	</div>
</div>

{include file='public/footer' }
<script>
	layui.config({
		base: '__ADMINST__layuiadmin/' //静态资源所在路径
	}).extend({
		index: 'lib/index' //主入口模块
	}).use(['index', 'useradmin', 'table','layer'], function(){
		var $ = layui.$
				,form = layui.form
				,table = layui.table;
	});

	//金额充值
	function addMoney(id){
		layer.prompt({
			formType: 0,
			shade: false, //遮罩透明度
			title:"请输入充值金额",
		}, function(value,index){
			$.ajax({
				type:"post",
				dataType:"json",
				url:"{:url('Member/moneyAdd')}",
				data:{id:id,money:value},
				success:function (data){
					if(data.code === 1){
						layer.close(index);
						layer.msg(data.msg,{time:2000},function(){
							if(data.url) location.href = data.url;
						});
					}else{
						layer.msg(data.msg,{time:2000});
					}
				}
			});
		});
	}

	//删除操作
	$(".del").click(function(){
		//获取删除信息和对应id
		var name = $(this).attr('data-name');
		var id = $(this).attr('data-id');
		//alert(name);
		layer.msg('是否删除\"' + name + '\"管理员?',{
			time:5000,
			shade:0.3,
			btn:['删除','取消'],
			yes:function() {
				//执行变更
				$.post("{:url('member/deletes')}",{id:id},function(data){
					if(data.code === 1){
						layer.msg(data.msg,{time:2000},function(){
							if(data.url) location.href = data.url;
						});
					}else{
						layer.msg(data.msg,{time:2000});
					}
				})
			}
		});
	});

	//状态变更
	function setStatus(id){
		layer.msg('确认要变更状态吗？',{
			time:5000,
			shade:0.3,
			btn:['确认','取消'],
			yes:function() {
				//执行变更
				$.post("{:url('member/setStatus')}",{id:id},function(data){
					if(data.code === 1){
						layer.msg(data.msg,{time:2000},function(){
							if(data.url) location.href = data.url;
						});
					}else{
						layer.msg(data.msg,{time:2000});
					}
				})
			}
		});
	}

	//全选功能
	function isCheck(){
		var IsCheck= document.getElementById("checkAll");
		if(IsCheck.checked == false){
			var groupC = document.getElementsByName("fav");
			for(var i=0;i<groupC.length;i++){
				groupC[i].checked=false;
			}
		}
		if(IsCheck.checked == true){
			var groupC = document.getElementsByName("fav");
			for(var i=0;i<groupC.length;i++){
				groupC[i].checked=true;
			}
		}
	}

	//批量删除
	function delAll(){
		var id=$("tbody input:checkbox");
		var ids=[];
		for(i=0;i<id.length;i++){
			if($(id[i]).is(":checked")){
				ids+=$(id[i]).val()+',';
			}
		}
		var delid = ids;
		if(delid == ""){
			layer.msg("当前未选择任何信息！",{icon:2,time:2000});
		}else{
			layer.msg('确认删除？',{
				time:5000,
				shade:0.3,
				btn:['确认','取消'],
				yes: function(){
					//执行删除
					$.post("{:url('Member/deletes')}",{id:delid},function(data){
						if(data.code === 1){
							layer.msg(data.msg,{time:2000},function(){
								if(data.url) location.href = data.url;
							});
						}else{
							layer.msg(data.msg,{time:2000});
						}
					})
				}
			});
		}
	}

	//点击搜索
	function so(){
		var keywords = $("#keywords").val();
		if(keywords == ""){
			layer.msg("请输入搜索内容！",{time:2000});
		}else{
			layer.open({
				title:"搜索内容",
				type:2,
				area:['100%','100%'],
				content: "{:url('Member/search')}"+"?keywords="+keywords,
				end:function(){
					location.reload();
				}
			});
		}
	}
	function updatemember(){
		$.ajax({
			type: 'POST',
			url: '{:url("admin/member/updatemember")}',
			dataType: "json",
			beforeSend: function() {
				index = layer.load();
			},
			success: function(data) {
				layer.msg(data.msg, {time: 2000}, function() {
					location.reload();
				});
			},
			complete: function() {
				layer.close(index);
			}
		});
	}

</script>
</body>
</html>
